//
//  LWPictureCell.swift
//  Microblog
//
//  Created by Roman on 17/1/10.
//  Copyright © 2017年 Roman. All rights reserved.
//

import UIKit

class LWPictureCell: UICollectionViewCell {
    
    
    //缩略图的自定义对象
    var LWPicturModel: LWPicturModel?{
        didSet{
            let url = URL(string: LWPicturModel?.bmiddle ?? "")
            iconView.sd_setImage(with: url)
           // print(LWPicturModel?.thumbnail_pic)
            //判断动图,如果以gif结尾,则显示为动图标志
            let urlString = url?.absoluteString ?? ""
            gifIcon.isHidden = !urlString.hasSuffix(".gif")
            
        }
    }
    
    
    //添加图片
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setupUI() {
        //添加子视图,
        self.contentView.addSubview(iconView)
        
        self.contentView.addSubview(gifIcon)
        //添加约束
        iconView.snp.makeConstraints { (make) in
            make.edges.equalTo(self.contentView)
        }
        
        gifIcon.snp.makeConstraints { (make) in
            make.trailing.equalTo(iconView.snp.trailing)
            make.bottom.equalTo(iconView.snp.bottom)
        }
        
    }
    
    //加载图片
    lazy var iconView: UIImageView = {
        let view = UIImageView()
        //缩放部分填充.
        view.contentMode = .scaleAspectFill
        //手写代码默认是不会裁剪
        view.clipsToBounds = true
        
        return view
        
    }()
    
    ///懒加载Gif图标
   lazy var gifIcon: UIImageView = {
     let iv = UIImageView()
    iv.image = #imageLiteral(resourceName: "timeline_image_gif")
    return iv
    
    }()
    
    

    
}
